/*
 * BasicRtpSocket.cpp
 *
 *  Created on: 2018年5月1日
 *      Author: zhengboyuan
 */

#include "BasicRtpSocket.h"

namespace av
{

BasicRtpSocket::BasicRtpSocket():
		m_connectionHandler(),
		m_initTime(),
		m_ssrc(1),
		m_seq(1)
{
}

BasicRtpSocket::~BasicRtpSocket()
{
}

bool BasicRtpSocket::setPeer(const char* ip, int port)
{
	comn::AutoCritSec lock(m_cs);

	if ((ip == NULL) || (strlen(ip) == 0))
	{
		m_peerAddr = comn::SockAddr();
		return true;
	}

	m_peerAddr.set(ip, port);
	return true;
}

void BasicRtpSocket::setConnectionHandler(ConnectionHandler handler)
{
	comn::AutoCritSec lock(m_cs);
	m_connectionHandler = handler;
}

void BasicRtpSocket::setTimeout(int ms)
{
	// pass
}

void BasicRtpSocket::setSsrc(uint32_t ssrc)
{
	comn::AutoCritSec lock(m_cs);
	m_ssrc = ssrc;
}

void BasicRtpSocket::fireConnectionState(int state)
{
	{
		comn::AutoCritSec lock(m_cs);
		if (!m_connectionHandler)
		{
			return;
		}
	}

	m_connectionHandler(this, state);
}



} /* namespace av */
